

var SysLogsModel = $.extend(TradeModel, {
    selRow: null,
    editor:{
        title: "属性",
        winid:'SysLogs_EditForm',
        formid:'SysLogs_EditForm_fm',
        width:720,
        height:300
    },
    postAction: 'add',
    url: '/sysmgr/syslogs',
    title: "标题",
    idField: "logId",
    titleField: "logId",
    toolbar: 'SysLogs_Toolbar',
    datagrid: 'SysLogs_Grid'
});

SysLogsModel.reload =function() {
    ReloadSysLogsList();
    $('#SysLogs_EditForm').dialog('close');
}


function fun_FindRowById(id) {
    var cRows = $('#SysLogs_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][SysLogsModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function ShowSysLogsEditForm(id) {
    SysLogsModel.selRow = fun_FindRowById(id);
    if (SysLogsModel.selRow == null) {
        SysLogsModel.selRow={};
        SysLogsModel.postAction = 'add';
    }
    else {
        SysLogsModel.postAction = 'update';
    }

    $('#params').html(SysLogsModel.selRow['params']);
    $('#remark').html(SysLogsModel.selRow['remark']);

    $('#SysLogs_EditForm').dialog({
        top: "50px",
        resizable: false,
        maximizable: false
    })
     .dialog('open').dialog('setTitle', ''+SysLogsModel.selRow['url']);
}
function SaveSysLogs() {
    SysLogsModel.submit();

}
function DelSysLogs( id,title) {
    SysLogsModel.del(id,title);
}

function SysLogsSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#SysLogs_Grid').datagrid('reload');
    }

}

function ReloadSysLogsList() {
    $('#SysLogs_Grid').datagrid('reload');
}



$(function () {
    $('#SysLogs_Grid').datagrid({
        pageSize: 10,
        fit: true,
        singleSelect: true,
        checkbox: false,
        rownumbers: false,
        fitColumns: true,
        pagination: true,
        method: 'post',
        idField: SysLogsModel.idField,
        treeField: SysLogsModel.titleField,
        url: Onluy.basePath()+SysLogsModel.url+'/list',
        loader:SysLogsModel.Loader,
        toolbar: '#SysLogs_Toolbar',
        columns: [
            [
                { field: 'intime', title: '日期', width:100, align: 'left',sortable:true },
                { field: 'url', title: '地址', width:200, align: 'left',sortable:true },
                { field: 'ip', title: 'IP', width:100, align: 'left',sortable:true },
                { field: 'userId', title: '用户编码', width:80, align: 'left',sortable:true },
                { field: 'departId', title: '部门编码', width:80, align: 'left',sortable:true },
                {
                    field: 'opt', title: '操作', width: 100, align: 'center',
                    formatter: function (value, rec) {
                        return '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/pencil.gif" onclick="ShowSysLogsEditForm(\'' + rec[SysLogsModel.idField] + '\');"   />'
                            + '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/delete.gif" onclick="DelSysLogs(\'' + rec[SysLogsModel.idField] + '\',\'' + rec[SysLogsModel.titleField] + '\');"  />';
                    }
                }
            ]
        ],


        onLoadError: function (res) {
            SysLogsModel.ShowException(res);
        },
        onLoadSuccess: function (data) {
            if(data.success){ }
            else if(data.msg){
                $.messager.alert('加载错误', data.msg );
            }
        },
        onDblClickRow: function (rowIndex, rowData) {
            ShowSysLogsEditForm(rowData[SysLogsModel.idField]);
        },
        onBeforeLoad: function (param) {
            $('#SysLogs_Grid').datagrid('clearSelections');
            param['catchKey'] = Math.random();
            param['name'] = $('#SysLogs_ss').searchbox('getName');
            param['value'] = $('#SysLogs_ss').searchbox('getValue');
        }
    });
    //设置分页控件
    var p = $('#SysLogs_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



